package com.by.controller;

import com.by.PageBean.SpuResult;
import com.by.common.core.bean.ResultBean;
import com.by.common.core.controller.BaseController;
import com.by.common.dao.bean.Page;
import com.by.entity.Spu;
import com.by.service.impl.SpuServiceImpl;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "spu产品管理")
@RequestMapping("/api/product")
public class SpuController extends BaseController {

    @Autowired
    SpuServiceImpl spuService;

    @ApiOperation("保存商品")
    @PostMapping("/spu")
    public ResultBean addProduct(@RequestBody Spu spu) {
        spuService.addProduct(spu);
        return success("1");
    }
    @ApiOperation("根据id查询商品")
    @GetMapping("/spu")
    public ResultBean getSpuById(@RequestParam(value = "id",required = true) Integer id) {
        Map map =spuService.getSpu(id);
        return success("商品详情",map);
    }


    @ApiOperation("分页查询所有商品")
    @PostMapping("/spu/all")
    public ResultBean getAllSpu(@RequestBody Page  p) {
       SpuResult ss= spuService.getSpuAll(p);

        return success("分页信息",ss);

    }
}
